<template>
  <view class="vip">
    <vip-nav />

    <view class="top">
      <view class="page-contaier">
        <view class="container">
          <view class="content">
            <image
              mode="widthFix"
              :src="vipInfos.icon || '@/static/image/vip/default.png'"
            />

            <view class="rule flex flex-middle" @click="showRule">
              <u-icon
                class="icon"
                name="question-circle"
                size="12"
                color="#fff"
              />
              规则说明
            </view>

            <view class="info">
              <view
                class="info-container"
                :style="'color: ' + (vipInfos.color || '#333')"
              >
                <view class="name">
                  {{ vipInfos.levelName || "未知会员等级" }}
                </view>
                <view class="time">
                  有效期至：
                  {{ expireTime }}
                </view>
                <u-line-progress
                  class="line"
                  height="2"
                  activeColor="#fff"
                  inactiveColor="rgba(255,255,255,0.3)"
                  :percentage="30"
                />
                <view class="tips">
                  <block v-if="vipInfos.nextLevelName">
                    再消费
                    {{ vipInfos.nextLevelNeedIntegral || "未知" }}
                    元可升至
                    {{ vipInfos.nextLevelName || "未知会员等级" }}
                  </block>
                  <block v-else>
                    尊贵的
                    {{ vipInfos.levelName || "未知会员等级" }}
                    为您服务是我们荣幸
                  </block>
                </view>
              </view>
            </view>

            <view class="btn flex flex-middle flex-center" @click="toOrder">
              前往下单
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="interest">
      <view class="title text-center">会员福利</view>
      <image src="@/static/image/vip/vip1.png" mode="widthFix" />
      <view
        class="line flex flex-middle flex-left"
        v-if="vipInfos.discount && vipInfos.discount < 100"
      >
        <view class="icons"></view>
        下单享受
        {{ discount }}
        折优惠
      </view>
    </view>
  </view>
</template>

<script>
import vipNav from "./components/vipNav";
import { mapGetters } from "vuex";

export default {
  components: {
    vipNav,
  },
  computed: {
    ...mapGetters(["vipInfo"]),
    expireTime() {
      let str = "长期有效";
      str = this.vipInfo?.expireTime?.slice(0, 10);
      return str;
    },
    discount() {
      return this.vipInfo.discount;
    },
    vipInfos() {
      return this.vipInfo || {};
    },
  },
  onLoad() {
    if (!this.vipInfo) this.$store.dispatch("getVipInfo");
  },
  methods: {
    toOrder() {
      this.$switchTab("/pages/home/index");
    },
    showRule() {
      this.$dialog({
        title: "规则说明",
        content:
          this.vipInfos.rule || "没有找到当前会员等级的规则，请联系客服咨询",
      });
    },
  },
};
</script>

<style scoped lang="scss">
.interest {
  position: relative;
  background: #000;
  border-radius: 16px 16px 0 0;
  margin-top: -20px;
  padding: 0 16px;

  .line {
    color: #fff;
    margin-top: 22px;

    .icons {
      width: 4px;
      height: 4px;
      background: #fff;
      border-radius: 50%;
      margin-right: 6px;
    }
  }

  image {
    width: 100%;
    margin-top: 10px;
  }

  .title {
    color: #fff;
    padding-top: 20px;
    font-size: 16px;
    font-weight: bold;
  }
}

.top {
  background: linear-gradient(180deg, #000000 0%, #5d5d5d 100%);

  .container {
    padding: 0 22px;
  }

  .content {
    position: relative;

    .btn {
      position: absolute;
      bottom: 14%;
      right: 16px;
      width: 62px;
      height: 18px;
      border: 1px solid #fff;
      color: #fff;
      border-radius: 18px;
      font-size: 12px;
    }

    .info {
      position: absolute;
      left: 0;
      top: 50%;
      width: 100%;
      margin-top: -36px;

      .tips {
        margin-top: 8px;
        color: #fff;
        font-size: 10px;
      }

      .line {
        margin-top: 18px;
      }

      .name {
        font-size: 24px;
        font-weight: bold;
      }

      .time {
        font-size: 10px;
      }

      &-container {
        padding: 0 16px;
      }
    }

    .rule {
      position: absolute;
      top: 12%;
      left: 0;
      color: #fff;
      font-size: 12px;

      .icon {
        margin-right: 4px;
      }
    }

    image {
      width: 100%;
    }
  }
}

.vip {
  min-height: 100vh;
  background: #000;
}
</style>